package com.wobito.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wobito.common.constants.SysConstants;
import com.wobito.mapper.BorrowReturnLogMapper;
import com.wobito.pojo.bean.BorrowLog;
import com.wobito.pojo.bean.ReturnLog;
import com.wobito.pojo.dto.api.GetBorrowReturnLogDTO;
import com.wobito.pojo.dto.log.BorrowLogByBookDTO;
import com.wobito.pojo.dto.log.BorrowLogByPersonDTO;
import com.wobito.pojo.dto.log.BorrowLogDTO;
import com.wobito.pojo.vo.log.BorrowReturnLogVO;
import com.wobito.service.IBorrowReturnLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lambyang
 * @since 2024-08-26
 */
@Service
public class BorrowReturnLogServiceImpl extends ServiceImpl<BorrowReturnLogMapper, ReturnLog> implements IBorrowReturnLogService {

    @Autowired
    private BorrowReturnLogMapper borrowReturnLogMapper;

    @Override
    public List<BorrowLogByBookDTO> selectBookBorrowByBookId(Long bookId) {
        return borrowReturnLogMapper.selectBookBorrowByBookId(bookId);
    }

    @Override
    public List<GetBorrowReturnLogDTO> selectBookLogList(Long bookId) {
        return borrowReturnLogMapper.selectBookLogList(bookId);
    }

    @Override
    public List<BorrowLogByPersonDTO> selectBookBorrowReturnByPersonId(Long personId) {
        return borrowReturnLogMapper.selectBookBorrowReturnByPersonId(personId);
    }

    @Override
    public List<BorrowLogDTO> selectBorrowReturnLogList(BorrowReturnLogVO borrowReturnLogVO) {
        List<BorrowLogDTO> borrowLogDTOS = new ArrayList<>();
        if (borrowReturnLogVO.getType() != null) {
            if (borrowReturnLogVO.getType().equals(SysConstants.BORROW_TYPE)) {
                borrowLogDTOS = borrowReturnLogMapper.selectBorrowLogList(borrowReturnLogVO);
            } else {
                borrowLogDTOS = borrowReturnLogMapper.selectReturnLogList(borrowReturnLogVO);
            }
        } else {
            borrowLogDTOS = borrowReturnLogMapper.selectBorrowReturnLogList(borrowReturnLogVO);
        }
        return borrowLogDTOS;
    }

    @Override
    public List<BorrowLogByPersonDTO> selectBorrowReturnLogById(Long personId) {
        return borrowReturnLogMapper.selectBookBorrowReturnByPersonId(personId);
    }

    @Override
    public int insertBorrowLog(BorrowLog borrowLog) {
        return borrowReturnLogMapper.insertBorrowLog(borrowLog);
    }

    @Override
    public int insertReturnLog(ReturnLog returnLog) {
        return borrowReturnLogMapper.insertReturnLog(returnLog);
    }
}
